import type {
	chapterListResInterface,
	chapterParamsInterface,
	courseAddObject,
	courseChapterResInfo,
	courseItemsInterface,
	courseOutlineObject,
	courseParamsInterface,
	lessonParamsInterface,
	ResPublishCourseInfo,
} from '../models/Course';
import instance from '../utils/request';

interface data<T> {
	status: number;
	msg: string;
	data: T;
}
// 添加课程
export const courseAddApi = (data: courseAddObject): Promise<data<{ courseId: string }>> => {
	return instance.post('/course/addCourseInfo', data);
};
// 修改课程信息
export const courseUpdateApi = (data: courseAddObject): Promise<data<null>> => {
	return instance.put('/course/updateCourseInfo', data);
};
// 根据课程id查询课程基本信息
export const getCourseInfoApi = (courseId: string): Promise<data<courseOutlineObject>> => {
	return instance.get(`/course/getCourseInfo/${courseId}`);
};
// 确定课程相关信息
export const getcourseItemApi = (courseId: string): Promise<data<ResPublishCourseInfo>> => {
	return instance.get(`/course/getPublishCourseInfo/${courseId}`);
};
// 根据章节id查询章节信息
export const getCourseChapterInfoApi = (chapterId: string): Promise<data<courseChapterResInfo>> => {
	return instance.get(`/eduservice/chapter/getChapterInfo/${chapterId}`);
};
// 添加章节
export const addCourseChapterApi = (data: chapterParamsInterface) => {
	return instance.post('/eduservice/chapter/addChapter', data);
};
// 编辑章节
export const updateCourseChapterApi = (data: chapterParamsInterface) => {
	return instance.put('/eduservice/chapter/updateChapter', data);
};
// 添加小节
export const addCourseVideoApi = (data: lessonParamsInterface) => {
	return instance.post('/video/addVideo', data);
};
// 根据课程id查询课程大纲列表
export const getCourseChapterApi = (courseId: string): Promise<data<chapterListResInterface>> => {
	return instance.get(`/eduservice/chapter/getChapterVideo/${courseId}`);
};

// 获取课程列表

export const courseListApi = (
	params: courseParamsInterface
): Promise<data<{ total: number; data: courseItemsInterface[] }>> => {
	return instance.get('/course/list', { params });
};

export const deleteCourseListApi = (courseId: string) => {
	return instance.delete(`/course/${courseId}`);
};
